//
//  HomePageCommentFollowCell.m
//  ShowYork
//
//  Created by hxh on 2020/11/23.
//  Copyright © 2020 hxh. All rights reserved.
//

#import "HomePageCommentFollowCell.h"

@interface HomePageCommentFollowCell ()
@property (nonatomic,strong)UIImageView *headerIcon;
@property (nonatomic,strong)UILabel *name;
@end

@implementation HomePageCommentFollowCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUI];
    }
    return self;
}

- (void)setUI{
    self.headerIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"defaut_header"]];
    self.headerIcon.layer.cornerRadius = 16;
    self.headerIcon.layer.masksToBounds = YES;
    [self.contentView addSubview:self.headerIcon];
    [self.headerIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.contentView).offset(16);
        make.bottom.equalTo(self.contentView).offset(-16);
        make.width.mas_equalTo(32);
        make.height.mas_equalTo(32).priorityHigh();
    }];
    self.name = [[UILabel alloc]init];
    self.name.text = @"xxx";
    self.name.font = [UIFont boldSystemFontOfSize:14];
    self.name.textColor = RGBA(51, 51, 51, 1);
    [self.contentView addSubview:self.name];
    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.left.equalTo(self.headerIcon.mas_right).offset(16);
    }];
}

+(instancetype)cellWithTableView:(UITableView *)tableView{
    NSString *ID = @"HomePageCommentFollowCell";
    HomePageCommentFollowCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[HomePageCommentFollowCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}
- (void)setModel:(UserInfoModel *)model{
    _model = model;
    self.name.text = model.realName;
    if ([model.id isEqualToNumber:[RPAppManager getCustomerId]]) {
        UserInfoModel *userInfo = [UserInfoModel userInfo];
        if (userInfo.imagePath.length == 0) {
            if (userInfo.sex.intValue == 0) {
                self.headerIcon.image = [UIImage imageNamed:@"defaut_header"];
            }else if (userInfo.sex.intValue == 1){
                self.headerIcon.image = [UIImage imageNamed:@"common_boy_tag"];
            }else{
                self.headerIcon.image = [UIImage imageNamed:@"common_girl_tag"];
            }
        }else{
            [self.headerIcon sd_setImageWithURL:[NSURL URLWithString:userInfo.imagePath] placeholderImage:[UIImage imageNamed:@"defaut_header"]];
        }
    }else{
        if (model.imagePath.length == 0) {
            if (model.sex.intValue == 0) {
                self.headerIcon.image = [UIImage imageNamed:@"defaut_header"];
            }else if (model.sex.intValue == 1){
                self.headerIcon.image = [UIImage imageNamed:@"common_boy_tag"];
            }else{
                self.headerIcon.image = [UIImage imageNamed:@"common_girl_tag"];
            }
        }else{
            [self.headerIcon sd_setImageWithURL:[NSURL URLWithString:model.imagePath] placeholderImage:[UIImage imageNamed:@"defaut_header"]];
        }

    }
}
@end
